package com.zline.foodraise.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.zline.foodraise.R;
import com.zline.foodraise.constant.Constant;
import com.zline.foodraise.listener.RecyclerItemClicked;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by heshantao on 15/7/8.
 * 发布动态下面的添加图片
 */
@EViewGroup(R.layout.release_dynamic_pic_item)
public class ReleaseDynamicPicItem extends RelativeLayout {
    private static final String LOG_TAG = ReleaseDynamicPicItem.class.getSimpleName();
    RecyclerItemClicked itemClicked;
    @ViewById(R.id.release_dynamic_pic_item_iv)
    ImageView iv;
    @ViewById(R.id.release_dynamic_delete_iv)
    ImageView delete_iv;
    int position;
    Context cxt;


    public ReleaseDynamicPicItem(Context context) {
        super(context);
        this.cxt = context;
    }


    public void bind(String imagePath, int position) {
        this.position = position;
        if (imagePath.equals(Constant.DEFAULT_PIC_URI)) {
            Bitmap bitmap = BitmapFactory.decodeResource(cxt.getResources(), R.mipmap.release_dynamic_add_pic);
            iv.setImageBitmap(bitmap);
        } else {
            ImageLoader.getInstance().displayImage(Constant.FILE_HEAD + imagePath, iv);
        }

        if (imagePath.equals(Constant.DEFAULT_PIC_URI)) {
            delete_iv.setVisibility(View.GONE);
        } else {
            delete_iv.setVisibility(View.VISIBLE);
        }

    }


    public void setRecyclerClickListener(RecyclerItemClicked listener) {
        this.itemClicked = listener;
    }


    @Click({R.id.release_dynamic_pic_item_iv, R.id.release_dynamic_delete_iv})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.release_dynamic_pic_item_iv:
                itemClicked.onRecyclerItemClicked(position);
                break;
            case R.id.release_dynamic_delete_iv:
                itemClicked.onRecyclerClickedDelete(position);
                break;
            default:
                break;
        }
    }
}
